//
//  AlbumImage.m
//  MPlayer
//
//  Created by 王俊 on 15/12/14.
//  Copyright © 2015年 王俊. All rights reserved.
//

#import "AlbumImage.h"
#import "defines.h"


@interface AlbumImage ()
@property(nonatomic,strong) UIImageView  *radioImage;



@end

@implementation AlbumImage

- (instancetype)init
{
    if (self = [super init]) {
        self.image = [UIImage imageNamed:@"play_disc"];
        _radioImage = [[UIImageView alloc]initWithFrame:CGRectMake((ALBUMIMAGEWIDTH - RADIOIMAGEWIDTH)/2, (ALBUMIMAGEHEIGHT - RADIOIMAGEHEIGHT)/2, RADIOIMAGEWIDTH, RADIOIMAGEHEIGHT)];
        _radioImage.clipsToBounds = true;
        _radioImage.layer.cornerRadius = RADIOIMAGEWIDTH/2.0;
        [self addSubview:_radioImage];
    }
    
    return self;
}

- (void)updateRadioImage:(UIImage*) image
{
    _radioImage.image = image;
}


- (void)rotationAni
{
    CABasicAnimation *rota = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    rota.fromValue = [NSNumber numberWithFloat:0.0];
    rota.toValue = [NSNumber numberWithFloat:M_PI * 2.0];
    rota.duration = 20.0;
    rota.repeatCount = MAXFLOAT;
    [self.layer addAnimation:rota forKey:nil];
    
}

- (void)pauseAni
{
    CFTimeInterval puaseTime = [self.layer convertTime:CACurrentMediaTime() fromLayer:nil];
    self.layer.speed = 0.0;
    self.layer.timeOffset = puaseTime;
}

- (void)resumeAni
{
    CFTimeInterval puaseTime = self.layer.timeOffset;
    self.layer.speed = 1.0;
    self.layer.timeOffset = 0.0;
    self.layer.beginTime = 0.0;
    CFTimeInterval timeSincePause = [self.layer convertTime:CACurrentMediaTime() fromLayer:nil] - puaseTime;
    self.layer.beginTime = timeSincePause;
    
}



@end
